/*工资反馈*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/activity/salaryFeedBackSuccessPage.dart';
import 'package:frametrim/app/app_navigator.dart';
import 'package:frametrim/utility/deviceUtils.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/views/appbar_black.dart';
import 'package:frametrim/views/button_circle.dart';
import 'package:frametrim/views/button_round.dart';
import 'package:frametrim/views/dialogs/commonDialog.dart';
import 'package:frametrim/views/multipleChoice/model/test_select_entity.dart';
import 'package:frametrim/views/multipleChoice/multipleChoiceView.dart';
import 'package:frametrim/views/multipleChoice/select_choice_chip.dart';
import 'package:frametrim/views/textfiled_text_linefeed.dart';

class SalaryFeedBackPage extends StatefulWidget {
  final String id;

  SalaryFeedBackPage(this.id);

  @override
  State<StatefulWidget> createState() => SalaryFeedBackState();
}

class SalaryFeedBackState extends State<SalaryFeedBackPage> {
  /*反馈原因*/
  List<TestSelectEntity> reason_list = [
    TestSelectEntity(title: '金额核算问题'),
    TestSelectEntity(title: '考勤问题'),
    TestSelectEntity(title: '薪资标准问题'),
    TestSelectEntity(title: '银行卡问题')
  ];
  late int textNum = 0;

  /*选中*/
  List<TestSelectEntity> choiced_list = [];

  TextEditingController _textController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _textController.addListener(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false, // 解决键盘顶起页面
      backgroundColor: SQColor.white,
      body: AnnotatedRegion(
        value: SystemUiOverlayStyle.dark,
        child: Column(
          children: <Widget>[
            Expanded(
                child: SingleChildScrollView(
              child: Container(
                child: Column(
                  children: <Widget>[
                    AppbarCenterTitle(
                      title: '工资反馈',
                      imgStr: 'image/imv_back.png',
                      titleColor: SQColor.black,
                    ),
                    buildPrompt(),
                    SizedBox(
                      height: 5,
                    ),
                    _buildReason(),
                    SizedBox(
                      height: 10,
                    ),
                    _buildProblem(),
                    Container(
                      padding: EdgeInsets.all(10),
                      child: Text(
                        '提示：问题处理需要一定时间，可能会造成本月工资延迟发放',
                        style: TextStyle(
                            color: SQColor.color_666666,
                            fontSize: 14,
                            height: 1.5),
                      ),
                    ),
                  ],
                ),
              ),
            )),
            Container(
              width: Screen.width - 20,
              height: 45,
              margin: EdgeInsets.only(bottom: 20),
              child: ButtonRoundView(
                textStr: '确认提交',
                textColor: SQColor.white,
                onPress: submit,
                buttonColor: SQColor.color_237BFC,
              ),
            ),
          ],
        ),
      ),
    );
  }

  /*温馨提示*/
  Widget buildPrompt() {
    return Container(
      padding: EdgeInsets.all(10),
      decoration: ShapeDecoration(
          color: SQColor.color_E5E9F9,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(6)))),
      margin: EdgeInsets.all(12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '温馨提示',
            style: TextStyle(fontSize: 16, color: SQColor.black),
          ),
          SizedBox(
            height: 8,
          ),
          RichText(
              text: TextSpan(children: <TextSpan>[
            TextSpan(
              text: '您的工资由飞翔劳务公司核算，如有疑问可联系负责人：',
              style: TextStyle(fontSize: 14, color: SQColor.color_222222),
            ),
            TextSpan(
                text: '18339995540',
                style: TextStyle(fontSize: 14, color: SQColor.primary),
                recognizer: TapGestureRecognizer()
                  ..onTap = () async {
                    /*点击事件*/
                    createPhoneDialog('18339995540');
                  }),
          ])),
        ],
      ),
    );
  }

  /*反馈原因*/
  Widget _buildReason() {
    return Container(
      width: Screen.width,
      // padding: EdgeInsets.only(left: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(left: 10),
            child: Text(
              '请选择反馈原因（可多选）',
              style: TextStyle(fontSize: 16, color: SQColor.black),
            ),
          ),
          SizedBox(
            height: 5,
          ),
          MultipleChoiceChip(
            dataList: reason_list,
            onSelectionChanged: (selectedList) {
              setState(() {
                selectedList.forEach((item) {
                  choiced_list.add(item as TestSelectEntity);
                  print('choiced_list==' + item.title);
                });
              });
            },
          )
        ],
      ),
    );
  }

  /*遇到的问题*/
  Widget _buildProblem() {
    return Container(
      width: Screen.width,
      padding: EdgeInsets.only(left: 12, right: 12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '请描述您遇到的问题',
            style: TextStyle(fontSize: 16, color: SQColor.black),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            decoration: ShapeDecoration(
                color: SQColor.color_EBEBEB,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(4)))),
            padding: EdgeInsets.all(10),
            height: 280,
            child: Expanded(
              child: TextfieldTextLineFeed(
                  '请描述您遇到的问题，不超500个字', 500, _textController),
            ),
          ),
        ],
      ),
    );
  }

/*拨打电话弹窗*/
  void createPhoneDialog(String phone) {
    showDialog<void>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext dialogContext) {
        return CommonDialog(
          title: '拨打电话',
          content: '18339995540？',
          button_left: '取消',
          onPress: () {
            DeviceUtils.launchTelURL(phone);
          },
        );
      },
    );
  }

/*确认提交弹窗*/
  void createSubmitDialog() {
    showDialog<void>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext dialogContext) {
        return CommonDialog(
          title: '提示',
          content: '问题处理需要时间，可能会造成您该月工资发放延迟，请您再次确认',
          button_left: '取消',
          button_right: '确认提交',
          onPress: () {
            print('提交');
            //关闭弹窗
            Navigator.pop(context);
            //退出当前页面
            // Navigator.pop(context,this);
            AppNavigator.push(context, SalaryFeedBackSuccessPage());
            // AppNavigator.pushWithName(context, SalaryFeedBackSuccessPage(), 'SalarySure');
          },
        );
      },
    );
  }

  /*提交*/
  void submit() {
    createSubmitDialog();
  }
}
